﻿/*
* 
*
* 功 能： N/A
* 类 名： BDPOVERMACHINE
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* 
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDPOVERMACHINE
	/// </summary>
	public partial class BDPOVERMACHINEDAL:IBDPOVERMACHINE
	{
		public BDPOVERMACHINEDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal DJID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDPOVERMACHINE");
			strSql.Append(" where DJID=:DJID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DJID", OracleType.Number,22)			};
			parameters[0].Value = DJID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDPOVERMACHINEModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDPOVERMACHINE(");
			strSql.Append("DJID,DJXH,DJMC,DJLB,SCCJ,DJGL,DJTDFS,DJZS,ISVALID,ISUSED,BZ)");
			strSql.Append(" values (");
			strSql.Append(":DJID,:DJXH,:DJMC,:DJLB,:SCCJ,:DJGL,:DJTDFS,:DJZS,:ISVALID,:ISUSED,:BZ)");
			OracleParameter[] parameters = {
					new OracleParameter(":DJID", OracleType.Number,18),
					new OracleParameter(":DJXH", OracleType.VarChar,30),
					new OracleParameter(":DJMC", OracleType.VarChar,30),
					new OracleParameter(":DJLB", OracleType.VarChar,30),
					new OracleParameter(":SCCJ", OracleType.VarChar,30),
					new OracleParameter(":DJGL", OracleType.Float,22),
					new OracleParameter(":DJTDFS", OracleType.VarChar,30),
					new OracleParameter(":DJZS", OracleType.Float,22),
					new OracleParameter(":ISVALID", OracleType.Number,4),
					new OracleParameter(":ISUSED", OracleType.Number,4),
					new OracleParameter(":BZ", OracleType.VarChar,300)};
			parameters[0].Value = model.DJID;
			parameters[1].Value = model.DJXH;
			parameters[2].Value = model.DJMC;
			parameters[3].Value = model.DJLB;
			parameters[4].Value = model.SCCJ;
			parameters[5].Value = model.DJGL;
			parameters[6].Value = model.DJTDFS;
			parameters[7].Value = model.DJZS;
			parameters[8].Value = model.ISVALID;
			parameters[9].Value = model.ISUSED;
			parameters[10].Value = model.BZ;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BDPOVERMACHINEModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDPOVERMACHINE set ");
			strSql.Append("DJXH=:DJXH,");
			strSql.Append("DJMC=:DJMC,");
			strSql.Append("DJLB=:DJLB,");
			strSql.Append("SCCJ=:SCCJ,");
			strSql.Append("DJGL=:DJGL,");
			strSql.Append("DJTDFS=:DJTDFS,");
			strSql.Append("DJZS=:DJZS,");
			strSql.Append("ISVALID=:ISVALID,");
			strSql.Append("ISUSED=:ISUSED,");
			strSql.Append("BZ=:BZ");
			strSql.Append(" where DJID=:DJID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DJXH", OracleType.VarChar,30),
					new OracleParameter(":DJMC", OracleType.VarChar,30),
					new OracleParameter(":DJLB", OracleType.VarChar,30),
					new OracleParameter(":SCCJ", OracleType.VarChar,30),
					new OracleParameter(":DJGL", OracleType.Float,22),
					new OracleParameter(":DJTDFS", OracleType.VarChar,30),
					new OracleParameter(":DJZS", OracleType.Float,22),
					new OracleParameter(":ISVALID", OracleType.Number,4),
					new OracleParameter(":ISUSED", OracleType.Number,4),
					new OracleParameter(":BZ", OracleType.VarChar,300),
					new OracleParameter(":DJID", OracleType.Number,18)};
			parameters[0].Value = model.DJXH;
			parameters[1].Value = model.DJMC;
			parameters[2].Value = model.DJLB;
			parameters[3].Value = model.SCCJ;
			parameters[4].Value = model.DJGL;
			parameters[5].Value = model.DJTDFS;
			parameters[6].Value = model.DJZS;
			parameters[7].Value = model.ISVALID;
			parameters[8].Value = model.ISUSED;
			parameters[9].Value = model.BZ;
			parameters[10].Value = model.DJID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal DJID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDPOVERMACHINE ");
			strSql.Append(" where DJID=:DJID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DJID", OracleType.Number,22)			};
			parameters[0].Value = DJID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string DJIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDPOVERMACHINE ");
			strSql.Append(" where DJID in ("+DJIDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public BDPOVERMACHINEModel GetModel(decimal DJID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select DJID,DJXH,DJMC,DJLB,SCCJ,DJGL,DJTDFS,DJZS,ISVALID,ISUSED,BZ from BDPOVERMACHINE ");
			strSql.Append(" where DJID=:DJID ");
			OracleParameter[] parameters = {
					new OracleParameter(":DJID", OracleType.Number,22)			};
			parameters[0].Value = DJID;

            BDPOVERMACHINEModel model = new BDPOVERMACHINEModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public BDPOVERMACHINEModel DataRowToModel(DataRow row)
		{
            BDPOVERMACHINEModel model = new BDPOVERMACHINEModel();
			if (row != null)
			{
				if(row["DJID"]!=null && row["DJID"].ToString()!="")
				{
					model.DJID=decimal.Parse(row["DJID"].ToString());
				}
				if(row["DJXH"]!=null)
				{
					model.DJXH=row["DJXH"].ToString();
				}
				if(row["DJMC"]!=null)
				{
					model.DJMC=row["DJMC"].ToString();
				}
				if(row["DJLB"]!=null)
				{
					model.DJLB=row["DJLB"].ToString();
				}
				if(row["SCCJ"]!=null)
				{
					model.SCCJ=row["SCCJ"].ToString();
				}
				if(row["DJGL"]!=null && row["DJGL"].ToString()!="")
				{
					model.DJGL=decimal.Parse(row["DJGL"].ToString());
				}
				if(row["DJTDFS"]!=null)
				{
					model.DJTDFS=row["DJTDFS"].ToString();
				}
				if(row["DJZS"]!=null && row["DJZS"].ToString()!="")
				{
					model.DJZS=decimal.Parse(row["DJZS"].ToString());
				}
				if(row["ISVALID"]!=null && row["ISVALID"].ToString()!="")
				{
					model.ISVALID=decimal.Parse(row["ISVALID"].ToString());
				}
				if(row["ISUSED"]!=null && row["ISUSED"].ToString()!="")
				{
					model.ISUSED=decimal.Parse(row["ISUSED"].ToString());
				}
				if(row["BZ"]!=null)
				{
					model.BZ=row["BZ"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select DJID,DJXH,DJMC,DJLB,SCCJ,DJGL,DJTDFS,DJZS,ISVALID,ISUSED,BZ ");
			strSql.Append(" FROM BDPOVERMACHINE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDPOVERMACHINE ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.DJID desc");
			}
			strSql.Append(")AS Row, T.*  from BDPOVERMACHINE T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDPOVERMACHINE";
			parameters[1].Value = "DJID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

